﻿#include <MaintenanceAndCorrection.h>


/**
 * @brief 构造函数
 */
MaintenanceAndCorrection::MaintenanceAndCorrection()
{
    udpClient=UdpClient::getInstance();
}

/**
 * @brief 析构函数
 */
MaintenanceAndCorrection::~MaintenanceAndCorrection()
{}

#pragma region 公用方法{

//恢复初始
Q_INVOKABLE void MaintenanceAndCorrection::restoreInitialState()
{

}

//单步停止运行
Q_INVOKABLE void MaintenanceAndCorrection::singleStop(QString serial){
    QString info=CommCommand::I().singleStop(serial);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

//停止实验
Q_INVOKABLE void MaintenanceAndCorrection::stop(){
    StaticProperties::runningList.clear();
    QString info="62 00 00 3A 00 06 04 00 E7 2F 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

//保存下发数据
Q_INVOKABLE void MaintenanceAndCorrection::saveData(int type){
    if(type==4){
        QString info="62 00 00 3C 00 05 0B E7 2F 55 AA";
        udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
    }
    else{
        QString info="62 00 00 3C 00 05 0B E7 2F 55 AA";
        udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
    }
}

/**
 * @brief MaintenanceAndCorrection::reset 复位
 * @param type 类型 0:初始位置 1:实验位置
 * @param serial 编号 0:全部复位 ,其他传对应编号 1-6注射器 7转盘 8纯化全部复位 9全部注射器 10放靶/转靶 11打靶
 * @param name 耗材名称 复位到初始位置可以不传
 */
Q_INVOKABLE void MaintenanceAndCorrection::reset(QString type,QString serial,QString name)
{
    __LOG_FSTART(type + " " + serial + " " + name);

    QString code=CommonHelper::Common().getItemCode("3",name);

    QString info=CommCommand::I().reset(type,serial,code);
    if(!info.isNull() && !info.isEmpty()){
        udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
    }
}


#pragma endregion}

#pragma region 放靶{

/**
 * @brief MaintenanceAndCorrection::runningBarrier 挡板校正
 * @param action
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningBarrier(QString action)
{
    QString data;

    //类型 阀门02
    data+= "2B ";

    data+=action=="遮挡"?"00 ":"01 ";

    QString info= QString("62 00 00 3C 00 06 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::writeAirpump 写入气泵参数
 * @param action
 * @param pressure
 */
Q_INVOKABLE void MaintenanceAndCorrection::writeAirpump(QString action,QString pressure)
{
    QString data;

    //类型 阀门02
    data+=action=="开阀门"?"00 ":"01 ";
    data+=CommonHelper::Common().TenToSixteen(pressure.toInt(),4)+" ";

    QString info= QString("62 00 00 3C 00 09 30 01 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::readAirpump 读取气泵参数
 * @param action
 */
Q_INVOKABLE void MaintenanceAndCorrection::readAirpump(QString action)
{
    QString data=action=="开阀门"?"00 ":"01 ";
    QString info=QString("62 00 00 3C 00 09 30 02 %1 00 00 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 打靶{

/**
 * @brief MaintenanceAndCorrection::runningFeed 进料
 * @param action
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningFeed(QString action)
{
    QString data;

    //类型 阀门02
    data+= "2C ";

    data+=action=="上移"?"00 ":"01 ";

    QString info= QString("62 00 00 3C 00 06 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::runningMovingTarget 旋转气缸运动
 * @param action
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningMovingTarget(QString action)
{
    QString data;

    //类型 阀门02
    data+= "2D ";

    data+=action=="进靶"?"00 ":"01 ";

    QString info= QString("62 00 00 3C 00 06 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::runningXDirection 送靶气缸运动
 * @param action 动作
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningXDirection(QString action)
{
    QString data;

    //类型 阀门02
    data+= "2E ";

    data+=action=="进靶"?"00 ":"01 ";

    QString info= QString("62 00 00 3C 00 06 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::readHeliumGasPump 读取氦气气泵压力值
 * @param type 动作类型
 */
Q_INVOKABLE void MaintenanceAndCorrection::readHeliumGasPump(QString type){
    QString data;

    //类型 阀门02
    data+=type=="开阀门"?"00 ":"01 ";

    QString info= QString("62 00 00 3C 00 09 35 02 %1 00 00 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::writeHeliumGasPump 写入氦气气泵压力值
 * @param type 动作类型
 * @param num 压力值
 */
Q_INVOKABLE void MaintenanceAndCorrection::writeHeliumGasPump(QString type,QString num){
    QString data;
    data+=type=="开阀门"?"00 ":"01 ";
    data+=CommonHelper::Common().TenToSixteen(num.toInt(),4);
    QString info= QString("62 00 00 3C 00 09 35 01 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 传靶{

#pragma region 夹爪{

/**
 * @brief MaintenanceAndCorrection::runningClampingJaw 执行夹爪
 * @param action 执行动作
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningClampingJaw(QString action)
{
    QString data;

    //类型 阀门02
    data+= "26 ";

    if(action=="松开"){
        data+="01 ";
    }
    else if(action=="夹紧"){
        data+="00 ";
    }
    QString info= QString("62 00 00 3C 00 06 %1FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 电机位置校正{

Q_INVOKABLE void MaintenanceAndCorrection::readMotorPosition(QString type,QString pos){
    QString data;

    if(type=="Z轴电机"){
        data+="01 ";
    }
    else if(type=="X轴电机"){
        data+="02 ";
    }
    else if(type=="开关盖电机"){
        data+="03 ";
    }
    else if(type=="蠕动泵"){
        data+="04 ";
    }

    if(pos=="吸靶位置"){
        data+="01 ";
    }
    else if(pos=="开关盖位置"){
        data+="02 ";
    }
    else if(pos=="放靶位置"){
        data+="03 ";
    }
    else if(pos=="开盖"){
        data+="04 ";
    }
    else if(pos=="关盖"){
        data+="05 ";
    }
    else if(pos=="吸液"){
        data+="06 ";
    }
    else if(pos=="打液"){
        data+="07 ";
    }
    data+="00 00 00 00";
    QString info= QString("62 00 00 3C 00 0C 27 02 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

Q_INVOKABLE void MaintenanceAndCorrection::writeMotorPosition(QString type,QString pos,QString step)
{
    QString data;

    if(type=="Z轴电机"){
        data+="01 ";
    }
    else if(type=="X轴电机"){
        data+="02 ";
    }
    else if(type=="开关盖电机"){
        data+="03 ";
    }
    else if(type=="蠕动泵"){
        data+="04 ";
    }


    if(pos=="吸靶位置"){
        data+="01 ";
    }
    else if(pos=="开关盖位置"){
        data+="02 ";
    }
    else if(pos=="放靶位置"){
        data+="03 ";
    }
    else if(pos=="开盖"){
        data+="04 ";
    }
    else if(pos=="关盖"){
        data+="05 ";
    }
    else if(pos=="吸液"){
        data+="06 ";
    }
    else if(pos=="打液"){
        data+="07 ";
    }
    data+=CommonHelper::Common().TenToSixteen(step.toInt(),8);
    QString info= QString("62 00 00 3C 00 0C 27 01 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 开关盖校正(拧盖){

Q_INVOKABLE void MaintenanceAndCorrection::readSwitchCover(QString direction){
    QString data=direction=="正向"?"00 ":"01 ";
    QString info=QString("62 00 00 3C 00 0D 28 02 %1 00 00 00 00 00 00 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

Q_INVOKABLE void MaintenanceAndCorrection::writeSwitchCover(QString direction,QString speed,QString step){
    QString data;
    data+=direction=="正向"?"00 ":"01 ";
    data+=CommonHelper::Common().TenToSixteen(speed.toInt(),4)+" ";
    data+=CommonHelper::Common().TenToSixteen(step.toInt(),8)+" ";

    QString info= QString( "62 00 00 3C 00 0D 28 01 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 蠕动泵{

Q_INVOKABLE void MaintenanceAndCorrection::runningPeristalticPump(QString module,QString type,QString speed,QString time){

    QString data;
    data+= module=="0"?"2A":"0D";
    if(type=="吸液"){
        data+="00 ";
    }
    else if(type=="打液"){
        data+="01 ";
    }
    else if(type=="停止"){
        data+="02 ";
    }
    if(type=="停止"){
        data+="00 00 00 00";
    }else{
        data+=CommonHelper::Common().TenToSixteen(speed.toInt(),4)+" ";
        data+=CommonHelper::Common().TenToSixteen(time.toInt(),4)+" ";
    }
    QString info= QString("62 00 00 3C 00 09 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 涨塞{

Q_INVOKABLE void MaintenanceAndCorrection::runningRisingCongestion(QString type){
    QString data=type=="夹紧"?"00":"01";
    QString info=QString("62 00 00 3C 00 06 32 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region Z向运动{

Q_INVOKABLE void MaintenanceAndCorrection::runningZMove( QString type){

    QString data=type=="上升"?"00":"01";
    QString info=QString("62 00 00 3C 00 06 33 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 吸盘{
/**
 * @brief MaintenanceAndCorrection::runningSucker 执行吸盘动作
 * @param type
 */
Q_INVOKABLE void MaintenanceAndCorrection::runningSucker(QString type){
    QString data=type=="吸取"?"00":"01";
    QString info=QString("62 00 00 3C 00 06 34 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::writeSucker 写入参数
 * @param type
 * @param num
 */
Q_INVOKABLE void MaintenanceAndCorrection::writeSucker(QString type,QString num){

    QString data;
    data+=type=="开阀门"?"00 ":"01 ";
    data+=CommonHelper::Common().TenToSixteen(num.toInt(),4);
    QString info=QString("62 00 00 3C 00 09 29 02 %1 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}


Q_INVOKABLE void MaintenanceAndCorrection::readSucker(QString type){
    QString data=type=="开阀门"?"00 ":"01 ";
    QString info=QString("62 00 00 3C 00 09 29 01 %1 00 00 FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma endregion}

#pragma region 纯化{

#pragma region 注射器{

/**
 * @brief MaintenanceAndCorrection::getSyringInfo 查询注射器信息
 * @return
 */
Q_INVOKABLE QVariantList MaintenanceAndCorrection::getSyringInfo(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql="Select * From SyringToalInfo order by Serial";
    query.exec(sql);
    QVariantList result;
    while (query.next())
    {
        QStringList list;
        for (int i = 0; i < query.record().count(); ++i) {
            if(i==1){
                list.append(CommonHelper::Common().getItemName("3",query.value(i).toString()));
            }else{
                list.append(query.value(i).toString());
            }
        }
        result.append(list);
    }
    return result;
}

/**
 * @brief MaintenanceAndCorrection::getSyringDetails 获取注射器详细信息
 * @param type
 * @return
 */
Q_INVOKABLE QVariantList MaintenanceAndCorrection::getSyringDetails(QString type){
    QString code=CommonHelper::Common().getItemCode("3",type);
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select Name,Type,InsideDiameter,PublicErrand,InitialPosition,"
                        "Rate,RateUnit,ReductionRatio,ScrewLead,CircleStep,StepNumber,TotalSteps "
                        "From SyringeMaintenance Where "
                        "ConsumablesTypes='%1'").arg(code);
    query.exec(sql);
    QVariantList result;
    while (query.next())
    {
        QStringList info;

        for (int i = 0; i < query.record().count(); ++i) {
            info.append(query.value(i).toString());
        }
        result.append(info);
    }
    return result;
}

//删除注射器(0全部删除 其他根据序号删除)
Q_INVOKABLE bool MaintenanceAndCorrection::delSyring(QString id){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    if(id=="0")
    {
        // 全部删除校验 -by cnr
        QStringList hctype;
        QString sql = "select value_2 from exe_config where type='0' and step='0' ";
        query.exec(sql);
        while (query.next())
        {
            hctype.append(query.value("value_2").toString());
        }
        QStringList hctype2;
        sql = "select ConsumablesTypes from SyringToalInfo ";
        query.exec(sql);
        while (query.next())
        {
            hctype2.append(query.value("ConsumablesTypes").toString());
        }
        for (const auto& element : hctype) {
            if (hctype2.contains(element)) {
                return false;
            }
        }
        sql="Delete From SyringToalInfo";
        query.exec(sql);
        sql="Delete From SyringeMaintenance";
        return  query.exec(sql);
    }
    else
    {
        // 单个删除校验 -by cnr
        QStringList hctype;
        QString sql = "select value_2 from exe_config where type='0' and step='0' ";
        query.exec(sql);
        while (query.next())
        {
            hctype.append(query.value("value_2").toString());
        }
        if(hctype.contains(id)){
            return false;
        }

        sql=QString("Delete From SyringeMaintenance Where ConsumablesTypes=("
                    "Select ConsumablesTypes "
                    "From SyringToalInfo Where Serial='%1')").arg(id);
        query.exec(sql);

        sql=QString("Delete From SyringToalInfo Where Serial='%1'").arg(id);
        query.exec(sql);

        sql=QString("Update SyringToalInfo Set Serial=Serial-1 Where Serial>'%1'").arg(id);
        query.exec(sql);
        return  true;
    }
}

//删除全部耗材
Q_INVOKABLE bool MaintenanceAndCorrection::alldelhc(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QStringList hctype;
    QString sql = "select value_2 from exe_config where type='0' and step='0' ";
    query.exec(sql);
    while (query.next())
    {
        hctype.append(query.value("value_2").toString());
    }
    QStringList hctype2;
    sql = "select ConsumablesTypes from SyringToalInfo ";
    query.exec(sql);
    while (query.next())
    {
        hctype2.append(query.value("ConsumablesTypes").toString());
    }
    for (const auto& element : hctype) {
        while (hctype2.contains(element)) {
            hctype2.removeOne(element);
        }
    }
    for(int i=0;i<hctype2.length();i++){
        QString id;
        sql=QString("select Serial from SyringToalInfo where ConsumablesTypes='%1' ").arg(hctype2[i]);
        query.exec(sql);
        while (query.next())
        {
            id=query.value("Serial").toString();
        }
        sql=QString("Delete From SyringeMaintenance Where ConsumablesTypes=("
                    "Select ConsumablesTypes "
                    "From SyringToalInfo Where Serial='%1')").arg(id);
        query.exec(sql);

        sql=QString("Delete From SyringToalInfo Where Serial='%1'").arg(id);
        query.exec(sql);

        sql=QString("Update SyringToalInfo Set Serial=Serial-1 Where Serial>'%1'").arg(id);
        query.exec(sql);
    }
    return true;
}

//添加注射器
Q_INVOKABLE bool MaintenanceAndCorrection::saveSyring(QString type,QString serial,QString ConsumablesTypes,QVariantList mapList)
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString code=CommonHelper::Common().getItemCode("3",ConsumablesTypes);

    QString sql=QString("Delete From SyringeMaintenance Where ConsumablesTypes='%1'").arg(code);
    query.exec(sql);

    int Num=1;
    foreach(QVariant syning,mapList){
        QStringList map=syning.value<QStringList>();
        sql=QString("Insert into SyringeMaintenance Values('%1','%2','%3','%4',"
                    "'%5','%6','%7','%8','%9','%10','%11','%12','%13','%14')").arg(code,QString::number(Num),map[0],
                map[1],map[2],map[3],map[4],map[5],map[6],map[7],map[8],map[9],map[10],map[11]);
        query.exec(sql);
        Num++;
    }
    Num--;
    if(type=="0")//新增
    {
        sql=QString("Insert or replace into SyringToalInfo Values('%1','%2','%3','%4')").arg(serial,code,QString::number(Num),CommonHelper::Common().GetDateTimeStr());
        query.exec(sql);
    }
    else//修改
    {
        sql=QString("Update SyringToalInfo set Num='%1',EditTime='%2' Where Serial='%3'").arg(QString::number(Num),CommonHelper::Common().GetDateTimeStr(),serial);
        query.exec(sql);
    }

    // 关联实验流程表格同步修改-by-cnr
    if(type=="1"){
        sql = QString("select id from exe_config where value_2 = '%1' ").arg(code);
        query.exec(sql);
        QStringList id;
        while (query.next()) {
            id.append(query.value("id").toString());
        }
        for(int i=0;i<id.length();i++){
            int NUMC=1;
            foreach(QVariant syning,mapList){
                QStringList map=syning.value<QStringList>();
                sql=QString("update exe_config set value_3 = '%1' where id='%2' and type='1' and value_1='%3' ").arg(map[1],id[i],QString::number(NUMC));
                query.exec(sql);
                NUMC++;
            }
        }

    }
    return  true;
}

//校验耗材类型是否存在
Q_INVOKABLE QStringList MaintenanceAndCorrection::canInsertConsumablesType(){
    QStringList result;
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql="Select value From Deftab Where id=3 and num not in(Select distinct ConsumablesTypes From SyringToalInfo)";
    query.exec(sql);
    while (query.next()) {
        result.append(query.value("value").toString());
    }
    return result;
}

//查询注射器数量
Q_INVOKABLE int MaintenanceAndCorrection::getSyringNum(QString name){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select value_2 From Deftab Where value='%3' and id='3'").arg(name);
    query.exec(sql);
    int result;
    while (query.next())
    {
        result=query.value("value_2").toInt();
    }
    return result;
}

//维护校正注射器执行
Q_INVOKABLE void MaintenanceAndCorrection::runningSyring(QString type,QString num, QString speed,QString pos){
    QString numStr=CommonHelper::Common().TenToSixteen(num.toInt(),2);
    QString speedStr=CommonHelper::Common().TenToSixteen(qRound(speed.toDouble()),4);
    QString posStr=CommonHelper::Common().TenToSixteen(qRound(pos.toDouble()),8);
    QString typeCode=CommonHelper::Common().getItemCode("3",type);
    QString typeStr=CommonHelper::Common().TenToSixteen(typeCode.toInt(),4);
    QString info=QString("62 00 00 3C 00 0E 06 03 %1 %2 %3 %4 E7 2F 55 AA").arg(numStr,typeStr,speedStr,posStr);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

//计算步数
Q_INVOKABLE QStringList MaintenanceAndCorrection::calculateSteps(QString speed,QString diameter, QString reductionRatio,QString screwLead,QString circleStep,QString distance){
    QStringList result;

    if(!speed.isNull()&&!reductionRatio.isNull()&&!screwLead.isNull()&&!circleStep.isNull()&&!distance.isNull()){
        QStringList reList=reductionRatio.split(':');
        double newSpeed=speed.toDouble();

        // 速度单位:ml/min 转成mm/s 距离从ml 转成 mm
        if(!diameter.isNull() && !diameter.isEmpty())
        {
            newSpeed=CommonHelper::Common().minToSecond(speed,diameter).toDouble();

            double r=diameter.toDouble()/2;
            double round=3.1415*r*r;
            distance=QString::number(distance.toDouble()*1000/round);
        }

        double stepNum=distance.toDouble()/screwLead.toDouble()*circleStep.toDouble()*reList[1].toDouble();
        double time=distance.toDouble()/newSpeed;
        double stepNumber= stepNum/time;

        result.append(QString::number(qRound(stepNumber)));
        result.append(QString::number(qRound(stepNum)));
    }else{
        result.append("");
        result.append("");
    }
    return result;
}

//获取注射器序号
Q_INVOKABLE QString MaintenanceAndCorrection::getSerial()
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString serial;
    QString sql="Select max(Serial)+1 as Serial From SyringToalInfo";
    query.exec(sql);
    while (query.next()) {
        serial=query.value("Serial").toString().isNull()?"1":query.value("Serial").toString();
    }
    return serial;
}

//校验注射器参数
Q_INVOKABLE QString MaintenanceAndCorrection::checkSyringParameter(QString type,QString nj,QString distance,QString speed,QString unit,QString jsb,QString dc,QString qb)
{
    QStringList list=type.split("ml");
    //    double volume= list[0].toDouble()*1000;
    if(unit=="mL/Min"){
        //        if(distance.toDouble()>list[0].toDouble())
        //        {

        //            double maxDistance=volume/area;
        //            if(distance.toDouble()>qFloor(maxDistance))
        //            {
        //                return QString("起始位置不能超出%1mL,请重新填写").arg(list[0]);
        //            }
        //        }

        //        double result = min * 1000 / (60*round);
        QString realJsb=jsb.split(":")[1];
        double maxSpeed=qFloor((48000*dc.toDouble())/(qb.toDouble()*realJsb.toDouble()));

        double maxMinSpeed=CommonHelper::Common().secondToMin(maxSpeed,nj.toDouble());
        if(speed.toDouble()>maxMinSpeed){
            return  QString("速度不能超出%1mL/Min,请重新填写").arg(QString::number(maxMinSpeed));
        }
    }
    else{
        //        double area=3.1415*nj.toDouble()*nj.toDouble()/4;
        //        double maxDistance=volume/area;
        //        if(distance.toDouble()>qFloor(maxDistance))
        //        {
        //            return QString("起始位置不能超出%1mm,请重新填写").arg(QString::number(qFloor(maxDistance)));
        //        }

        QString realJsb=jsb.split(":")[1];
        double maxSpeed=qFloor((48000*dc.toDouble())/(qb.toDouble()*realJsb.toDouble()));

        if(speed.toDouble()>maxSpeed){
            return  QString("速度不能超出%1mm/s,请重新填写").arg(QString::number(maxSpeed));
        }
    }
    return "";
}

//导出
Q_INVOKABLE int MaintenanceAndCorrection::exportSyringConfig(QString id)
{

    QString path="";
    QString  savePath = QFileDialog::getSaveFileName(NULL, "保存", path,"Wlk files(*.txt)");
    if(savePath.isEmpty()&&savePath.isNull()){
        return -1;
    }

    QFile file(savePath);
    file.open(QIODevice::Append);

    QTextStream out(&file);  // QTextStream会自动将 Unicode 编码同操作系统的编码进行转换
    QTextCodec* codec = QTextCodec::codecForName("GBK");
    out.setCodec(codec);

    QString code= CommonHelper::Common().getItemCode("3",id);
    out<<id+"\n";//标记耗材名称

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select * From SyringeMaintenance Where ConsumablesTypes='%1' ").arg(code);
    query.exec(sql);

    while (query.next())
    {
        QString addSql=QString("Insert into SyringeMaintenance Values('%1','%2','%3','%4','%5','%6','%7','%8',"
                               "'%9','%10','%11','%12','%13','%14')").arg(
                    query.value("ConsumablesTypes").toString(),query.value("Id").toString(),
                    query.value("Name").toString(),query.value("Type").toString(),
                    query.value("InsideDiameter").toString(),query.value("PublicErrand").toString(),
                    query.value("InitialPosition").toString(), query.value("Rate").toString(),
                    query.value("RateUnit").toString(),query.value("ReductionRatio").toString(),
                    query.value("ScrewLead").toString(),query.value("CircleStep").toString(),
                    query.value("StepNumber").toString(),query.value("TotalSteps").toString());
        out<<addSql+"\n";
    }

    file.close();
    return true;
}

//导入
Q_INVOKABLE int MaintenanceAndCorrection::importSyringConfig()
{
    QStringList sfilePath;
    QFileDialog *fDialog=new QFileDialog(NULL,"file dlg","","Txt files(*.txt)");
    if(fDialog->exec()==QFileDialog::Accepted)
    {
        sfilePath = fDialog->selectedFiles();
    }
    if(sfilePath.length()<=0)
    {
        return  1;
    }
    QString filepath = sfilePath[0];
    QFile file(filepath);
    if(!file.exists()){
        return -1;
    }
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream txtInput(&file);

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    int i=0;
    QString code;
    bool exist=false;
    db.transaction();
    while (!txtInput.atEnd())
    {
        QString lineStr = txtInput.readLine();

        if(i==0)
        {
            QString sql=QString("Select count(*) Num From Deftab Where value='%1' and id='3'").arg(lineStr);
            query.exec(sql);
            while (query.next()) {
                exist=query.value("Num").toInt()>0;
            }
            if(exist)
            {
                code=CommonHelper::Common().getItemCode("3",lineStr);
                QString  sql=QString("Delete From SyringeMaintenance Where ConsumablesTypes='%1'").arg(code);
                query.exec(sql);
            }
            else
            {
                QString sql="Select max(Num)+1 as Serial From Deftab Where id='3'";
                query.exec(sql);
                while (query.next()) {
                    code=query.value("Serial").toString().isNull()?"1":query.value("Serial").toString();
                }

                sql=QString("Insert into Deftab values('3','0','%1','%2','6')").arg(code,lineStr);
                query.exec(sql);
            }
            i++;
        }
        else
        {
            if(!lineStr.contains("Insert into SyringeMaintenance Values")){
                db.rollback();
                return -2;
            }

            QStringList strList = lineStr.split("'");
            strList[1]=code;
            lineStr = strList.join("'");
            query.exec(lineStr);
        }
    }
    db.commit();
    if(exist)
    {
        bool existSyring=false;
        QString sql=QString("Select count(*) Num From SyringToalInfo Where ConsumablesTypes='%1'").arg(code);
        query.exec(sql);
        while (query.next())
        {
            existSyring=query.value("Num").toInt()>0;
        }

        if(existSyring){
            sql=QString("Update SyringToalInfo Set Num=(Select count(*) From SyringeMaintenance Where ConsumablesTypes='%1'),EditTime='%2' Where ConsumablesTypes='%1'").arg(code,CommonHelper::Common().GetDateTimeStr());
            query.exec(sql);
        }
        else{
            QString sql=QString("Insert into SyringToalInfo Values((Select Case When max(Serial)+1 isNull then 1 else max(Serial)+1 end From SyringToalInfo),'%1',(Select count(*) From SyringeMaintenance Where ConsumablesTypes='%1'),'%2')").arg(code,CommonHelper::Common().GetDateTimeStr());
            query.exec(sql);
        }
    }
    else{
        QString sql=QString("Insert into SyringToalInfo Values((Select Case When max(Serial)+1 isNull then 1 else max(Serial)+1 end From SyringToalInfo),'%1',(Select count(*) From SyringeMaintenance Where ConsumablesTypes='%1'),'%2')").arg(code,CommonHelper::Common().GetDateTimeStr());
        query.exec(sql);
    }
    QString sql=QString("Update Deftab Set value_2=(Select Count(*) From SyringeMaintenance Where ConsumablesTypes='%1') Where id='3' and num='%1'").arg(code);
    query.exec(sql);

    return 0;
}


#pragma endregion}

#pragma region 阀门{

//维护校正执行阀门
Q_INVOKABLE void MaintenanceAndCorrection::runningValve(QString type ,QString List){

    QString data;

    //类型 阀门02
    data+= "01 ";

    if(type=="开启"){
        QStringList openList=List.split(",");
        for(int m=1;m<=3;m++){
            QString binaryInfo;
            for(int n=8*m;n>=1+8*(m-1);n--){
                if(openList.contains(QString::number(n)))
                {
                    binaryInfo += "0";
                }
                else
                {
                    binaryInfo += "1";
                }
            }
            data+=CommonHelper::Common().binaryToHex(binaryInfo)+" ";
        }
    }
    else if(type=="关闭"){
        QStringList closeList=List.split(",");
        for(int m=1;m<=3;m++){
            QString binaryInfo;
            for(int n=8*m;n>=1+8*(m-1);n--){
                if(closeList.contains(QString::number(n)))
                {
                    binaryInfo += "1";
                }
                else
                {
                    binaryInfo += "0";
                }
            }
            data+=CommonHelper::Common().binaryToHex(binaryInfo)+" ";
        }
    }
    QString info= QString("62 00 00 3C 00 08 %1FB 53 55 AA").arg(data);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma region 转盘{

//读取
Q_INVOKABLE void MaintenanceAndCorrection::readPos(QString pos){
    QString posStr;
    if(pos.contains("接液位置")){
        pos.remove("接液位置");
        posStr=CommonHelper::Common().TenToSixteen(pos.toInt(),2);
    }else{
        pos.remove("盖盖位置");
        posStr=CommonHelper::Common().TenToSixteen(pos.toInt()+10,2);
    }
    QString info=QString("62 00 00 3C 00 07 08 07 %1 E7 2F 55 AA").arg(posStr);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

//执行转盘
Q_INVOKABLE void MaintenanceAndCorrection::turnTurnTable(QString pos,QString step){
    QString posStr;
    if(pos.contains("接液位置")){
        pos.remove("接液位置");
        posStr=CommonHelper::Common().TenToSixteen(pos.toInt(),2);
    }else{
        pos.remove("盖盖位置");
        posStr=CommonHelper::Common().TenToSixteen(pos.toInt()+10,2);
    }
    QString stepInfo= CommonHelper::Common().TenToSixteen(step.toInt(),8);
    QString info=QString("62 00 00 3C 00 0B 09 07 %1 %2 E7 2F 55 AA").arg(posStr,stepInfo);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

//设置转盘初始位置
Q_INVOKABLE void MaintenanceAndCorrection::setInitialPosition(QString pos,QString type)
{
    QString realPos=pos;
    if(pos.contains("接液位置")){
        realPos=pos.remove("接液位置");
    }
    else if(pos.contains("盖盖位置")){
        realPos=QString::number(pos.remove("盖盖位置").toInt()+10);
    }

    QString code= CommonHelper::Common().getItemCode("3",type);
    QString posStr=CommonHelper::Common().TenToSixteen(realPos.toInt(),2);
    QString typeStr=CommonHelper::Common().TenToSixteen(code.toInt(),4);
    QString info=QString("62 00 00 3C 00 09 0A 07 %1 %2 E7 2F 55 AA").arg(posStr,typeStr);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Insert or Replace into TurnTableInformation Values('%1','%2')").arg(code,pos);
    query.exec(sql);
}

#pragma endregion}

#pragma region 气泵{

//设置 读取气泵压力值
Q_INVOKABLE void MaintenanceAndCorrection::setAirPumpPressure(QString open,QString close)
{
    QString info=CommCommand::I().AirPumpPressure("1",open,close);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

Q_INVOKABLE void MaintenanceAndCorrection::readAirPumpPressure(){
    QString info= CommCommand::I().AirPumpPressure("2","0","0");
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

#pragma endregion}

#pragma endregion}

#pragma region 通信日志{

//查询通信日志
Q_INVOKABLE QVariantList MaintenanceAndCorrection::getLog(){
    return  StaticProperties::logInfo;
}

//删除通信日志
Q_INVOKABLE void MaintenanceAndCorrection::delLog(){
    StaticProperties::logInfo.clear();
    emit dellog();
}

//导出通信日志
Q_INVOKABLE void MaintenanceAndCorrection::exportLog(){
    QString path="/path/to/default/";
    QString  savePath = QFileDialog::getSaveFileName(NULL, "保存", path,"Wlk files(*.txt)");
    if(savePath.isEmpty()&&savePath.isNull()){
        return;
    }

    QFile file(savePath);
    file.open(QIODevice::Append);
    QDateTime current=QDateTime::currentDateTime();
    QString dateStr=current.toString("yyyy-MM-dd ");
    foreach(QVariant log,StaticProperties::logInfo){
        QStringList map=log.value<QStringList>();
        file.write((map[1]+": \n"+map[2] +": " +map[3] +"["+dateStr+map[0] + "]  " + "\n").toUtf8());
    }
    file.close();
}

#pragma endregion}

#pragma region 故障信息{

//获取故障信息
Q_INVOKABLE QJsonArray MaintenanceAndCorrection::getFaultInformation()
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString rule;
    QString sql;
    if(StaticProperties::softType==0){
        rule="";
    }
    else if(StaticProperties::softType==1){
        rule="Where Module not like '%4%'";
    }
    else if(StaticProperties::softType==2){
        rule="Where Module like '%4%'";
    }


    sql=QString("Select Serial,Module,ErrorCode,ErrorName,ErrorMethod,IsBlocked From FaultInformation %1").arg(rule);
    query.exec(sql);

    QStringList serial;
    QStringList module;
    QStringList errorCode;
    QStringList errorName;
    QStringList errorMethod;
    QStringList isBlocked;

    while (query.next()) {
        serial.append(query.value("Serial").toString());
        QString moduleStr;
        moduleStr=query.value("Module").toString();
        QStringList moduleList=moduleStr.split(",");
        QString realModule;
        for(int i=0;i<moduleList.length();i++){
            realModule+=CommonHelper::Common().getCurrentExpTypeName(moduleList[i].toInt())+",";
        }
        realModule=realModule.left(realModule.length()-1);
        module.append(realModule);
        errorCode.append(query.value("ErrorCode").toString());
        errorName.append(query.value("ErrorName").toString());
        errorMethod.append(query.value("ErrorMethod").toString());
        isBlocked.append(query.value("IsBlocked").toString());
    }
    QJsonArray result;
    QJsonObject rec;
    for(int i = 0; i < serial.size(); ++i) {
        rec.insert("serial", serial[i]);
        rec.insert("module",module[i]);
        rec.insert("errorCode", errorCode[i]);
        rec.insert("errorName", errorName[i]);
        rec.insert("errorMethod", errorMethod[i]);
        rec.insert("isBlocked", isBlocked[i]);

        result.append(rec);
    }
    return result;
}

//修改故障信息(不包含屏蔽)
Q_INVOKABLE void MaintenanceAndCorrection::updateFaultInformation(QString module,QString serial,QString errorName,QString errorMethod)
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QStringList moduleList=module.split(",");
    QString realModule;
    for(int i=0;i<moduleList.length();i++){
        realModule+=QString::number(CommonHelper::Common().getCurrentExpTypeCode(moduleList[i]))+",";
    }
    realModule=realModule.left(realModule.length()-1);
    QString sql=QString("Update FaultInformation set Module='%1',ErrorName='%2',"
                        "ErrorMethod='%3' Where Serial='%4'").arg(realModule,errorName,errorMethod,serial);
    query.exec(sql);
}

//添加故障信息(默认放靶)
Q_INVOKABLE bool MaintenanceAndCorrection::addFaultInformation(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString serial;
    QString sql="Select max(serial) serial From FaultInformation";
    query.exec(sql);
    while (query.next()) {
        serial=query.value("serial").toString();
    }

    QString maxErrorCode;
    sql=QString("Select ErrorCode From FaultInformation Where serial='%2'").arg(serial);
    query.exec(sql);
    while (query.next())
    {
        maxErrorCode=query.value("ErrorCode").toString();
    }
    int tenCode= CommonHelper::Common().SixteenToTen(maxErrorCode).toInt();
    QString newCode=CommonHelper::Common().TenToSixteen(tenCode+1,2).toUpper();
    sql=QString("Insert into FaultInformation values('1','%1','%2','','是','否')").arg(QString::number(serial.toInt()+1),newCode);
    return query.exec(sql);
}

//修改屏蔽状态
Q_INVOKABLE void MaintenanceAndCorrection::blockFaultInformation(QString serial,QString errorCode, QString isBlocked){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Update FaultInformation set IsBlocked='%1' Where Serial='%2'").arg(isBlocked,serial);
    query.exec(sql);

    QString finalInfo=QString("62 00 00 3C 00 07 37 %1 %2 E7 2F 55 AA").arg(errorCode,isBlocked=="是"?"01":"00");
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(finalInfo));
}

#pragma endregion}

#pragma region 检测信息{

//获取检测信息
Q_INVOKABLE QJsonArray MaintenanceAndCorrection::getDetectorInformation()
{
    QString rule;
    if(StaticProperties::softType==0){
        rule="";
    }
    else if(StaticProperties::softType==1){
        rule="Where Module not like '%纯化%'";
    }
    else if(StaticProperties::softType==2){
        rule="Where Module like '%纯化%'";
    }

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select Serial,Module,Info,IsBlocked From DetectorInformation %1").arg(rule);
    query.exec(sql);

    QStringList serial;
    QStringList module;
    QStringList info;
    QStringList isBlocked;

    while (query.next()) {
        serial.append(query.value("Serial").toString());
        module.append(query.value("Module").toString());
        info.append(query.value("Info").toString());
        isBlocked.append(query.value("IsBlocked").toString());
    }
    QJsonArray result;
    QJsonObject rec;
    for(int i = 0; i < serial.size(); ++i) {
        rec.insert("serial", serial[i]);
        rec.insert("module",module[i]);
        rec.insert("info", info[i]);
        rec.insert("isBlocked", isBlocked[i]);

        result.append(rec);
    }
    return result;
}

//修改检测信息
Q_INVOKABLE void MaintenanceAndCorrection::updateDetectorInformation(QString serial,QString module,QString isBlocked)
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Update DetectorInformation set Module='%1',IsBlocked='%2' Where Serial='%3'").arg(module,isBlocked,serial);
    query.exec(sql);
    QString byteInfo;
    for(int i=1;i<4;i++){
        sql=QString("WITH RECURSIVE sequence(id) AS ("
                    "SELECT 1 "
                    "UNION ALL "
                    "SELECT id + 1 FROM sequence WHERE id < 8"
                    ") "
                    "SELECT "
                    "sequence.id, "
                    "COALESCE(DetectorInformation.IsBlocked, '否') AS value "
                    "FROM sequence "
                    "LEFT JOIN DetectorInformation  "
                    "ON sequence.id = DetectorInformation.ProtocolLocation and DetectorInformation.ByteCount='%1' "
                    "order by sequence.id").arg(QString::number(i));
        query.exec(sql);
        QString info;
        while (query.next()) {
            info+=query.value("value").toString()=="是"?"1":"0";
        }
        byteInfo+=CommonHelper::Common().binaryToHex(info)+" ";
    }
    QString finalInfo=QString("62 00 00 3C 00 08 36 %1 E7 2F 55 AA").arg(byteInfo);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(finalInfo));
}



#pragma endregion}

#pragma region 组件配置{

/**
 * @brief MaintenanceAndCorrection::getComponentInfoList
 * @param module 传数字(1放靶,2打靶,3转靶,4纯化)
 * @return
 */
Q_INVOKABLE QVariantList MaintenanceAndCorrection::getComponentInfoList(QString module){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select Serial,ComponentName,IsUsed From ComponentInfo Where module='%1'").arg(module);
    query.exec(sql);
    QVariantList result;
    while (query.next())
    {
        QStringList list;
        for (int i = 0; i < query.record().count(); ++i) {

            list.append(query.value(i).toString());
        }
        result.append(list);
    }
    return result;
}

/**
 * @brief MaintenanceAndCorrection::getComponentUseStatus
 * @param module 模块 传数字(1放靶,2打靶,3转靶,4纯化)
 * @param serial 序号
 * @return
 */
Q_INVOKABLE int MaintenanceAndCorrection::getComponentUseStatus(QString module,QString serial){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select IsUsed From ComponentInfo Where module='%1' and Serial='%2'").arg(module,serial);
    query.exec(sql);

    int isUsed;

    while (query.next()) {
        isUsed=query.value("IsUsed").toInt();
    }

    return isUsed;
}

/**
 * @brief MaintenanceAndCorrection::saveComponentInfo 保存组件信息
 * @param module 模块 传数字(1放靶,2打靶,3转靶,4纯化)
 * @param info 二维数组
 */
Q_INVOKABLE void MaintenanceAndCorrection::saveComponentInfo(QString module,QVariantList info){

    QSqlDatabase db=dbHelper::openConnection();
    QSqlQuery query(db);

    QString sql;
    db.transaction();
    sql=QString("Delete From ComponentInfo Where Module='%1'").arg(module);
    query.exec(sql);

    foreach(QVariant program,info){
        QStringList map=program.value<QStringList>();
        sql=QString("Insert into ComponentInfo Values('%1','%2','%3','%4')").arg(map[0],module,map[1],map[2]);
        query.exec(sql);
    }
    db.commit();
}

#pragma endregion}

#pragma region 维护校正{
/**
 * @brief MaintenanceAndCorrection::maintenanceAction 维护所有动作
 * @param action 动作
 */
Q_INVOKABLE void MaintenanceAndCorrection::maintenanceAction(QString action){
    QMap<QString, QString> orderMap;
    orderMap.insert("挡板运动遮挡","62 00 00 3C 00 06 52 00 00 00 55 AA");
    orderMap.insert("挡板运动打开","62 00 00 3C 00 06 52 01 00 00 55 AA");
    orderMap.insert("热室端送靶打开","62 00 00 3C 00 06 53 00 00 00 55 AA");
    orderMap.insert("热室端送靶关闭","62 00 00 3C 00 06 53 01 00 00 55 AA");
    orderMap.insert("梭体上靶上移","62 00 00 3C 00 06 73 00 00 00 55 AA");
    orderMap.insert("梭体上靶下移","62 00 00 3C 00 06 73 01 00 00 55 AA");
    orderMap.insert("水冷头旋转(垂直)","62 00 00 3C 00 06 74 00 00 00 55 AA");
    orderMap.insert("水冷头旋转(水平)","62 00 00 3C 00 06 74 01 00 00 55 AA");
    orderMap.insert("退靶","62 00 00 3C 00 06 75 00 00 00 55 AA");
    orderMap.insert("进靶","62 00 00 3C 00 06 75 01 00 00 55 AA");
    orderMap.insert("正压阀1开启","62 00 00 3C 00 06 76 00 00 00 55 AA");
    orderMap.insert("正压阀1关闭","62 00 00 3C 00 06 76 01 00 00 55 AA");
    orderMap.insert("正压阀2开启","62 00 00 3C 00 06 77 00 00 00 55 AA");
    orderMap.insert("正压阀2关闭","62 00 00 3C 00 06 77 01 00 00 55 AA");
    orderMap.insert("正压阀3开启","62 00 00 3C 00 06 78 00 00 00 55 AA");
    orderMap.insert("正压阀3关闭","62 00 00 3C 00 06 78 01 00 00 55 AA");
    orderMap.insert("负压阀1开启","62 00 00 3C 00 06 79 00 00 00 55 AA");
    orderMap.insert("负压阀1关闭","62 00 00 3C 00 06 79 01 00 00 55 AA");
    orderMap.insert("负压阀2开启","62 00 00 3C 00 06 7A 00 00 00 55 AA");
    orderMap.insert("负压阀2关闭","62 00 00 3C 00 06 7A 01 00 00 55 AA");
    orderMap.insert("负压阀3开启","62 00 00 3C 00 06 7B 00 00 00 55 AA");
    orderMap.insert("负压阀3关闭","62 00 00 3C 00 06 7B 01 00 00 55 AA");
    orderMap.insert("水冷机开启","62 00 00 3C 00 06 7C 00 00 00 55 AA");
    orderMap.insert("水冷机关闭","62 00 00 3C 00 06 7C 01 00 00 55 AA");
    orderMap.insert("水路阀1开启","62 00 00 3C 00 06 7D 00 00 00 55 AA");
    orderMap.insert("水路阀1关闭","62 00 00 3C 00 06 7D 01 00 00 55 AA");
    orderMap.insert("水路阀2开启","62 00 00 3C 00 06 7E 00 00 00 55 AA");
    orderMap.insert("水路阀2关闭","62 00 00 3C 00 06 7E 01 00 00 55 AA");
    orderMap.insert("水路阀3开启","62 00 00 3C 00 06 7F 00 00 00 55 AA");
    orderMap.insert("水路阀3关闭","62 00 00 3C 00 06 7F 01 00 00 55 AA");
    orderMap.insert("氦气阀1开启","62 00 00 3C 00 06 80 00 00 00 55 AA");
    orderMap.insert("氦气阀1关闭","62 00 00 3C 00 06 80 01 00 00 55 AA");
    orderMap.insert("氦气阀2开启","62 00 00 3C 00 06 81 00 00 00 55 AA");
    orderMap.insert("氦气阀2关闭","62 00 00 3C 00 06 81 01 00 00 55 AA");
    orderMap.insert("抱闸状态-锁止","62 00 00 3C 00 06 82 00 00 00 55 AA");
    orderMap.insert("抱闸状态-松开","62 00 00 3C 00 06 82 01 00 00 55 AA");
    orderMap.insert("吸取梭体开启","62 00 00 3C 00 06 83 00 00 00 55 AA");
    orderMap.insert("吸取梭体关闭","62 00 00 3C 00 06 83 01 00 00 55 AA");
    orderMap.insert("加速端回靶启动","62 00 00 3C 00 06 84 00 00 00 55 AA");
    orderMap.insert("加速端回靶停止","62 00 00 3C 00 06 84 01 00 00 55 AA");
    orderMap.insert("冷却设置水气全开","62 00 00 3C 00 07 86 00 00 00 00 55 AA");
    orderMap.insert("冷却设置水气全关","62 00 00 3C 00 07 86 01 01 00 00 55 AA");
    orderMap.insert("水气全开","62 00 00 3C 00 07 86 00 00 00 00 55 AA");
    orderMap.insert("水气全关","62 00 00 3C 00 07 86 01 00 00 00 55 AA");
    orderMap.insert("气冷开启","62 00 00 3C 00 07 86 00 01 00 00 55 AA");
    orderMap.insert("气冷关闭","62 00 00 3C 00 07 86 00 01 00 00 55 AA");
    orderMap.insert("梭体组合运行一键退靶","62 00 00 3C 00 06 87 00 00 00 55 AA");
    orderMap.insert("梭体组合运行一键进靶","62 00 00 3C 00 06 87 01 00 00 55 AA");
    orderMap.insert("梭体夹爪夹紧","62 00 00 3C 00 07 19 01 01 00 00 55 AA");
    orderMap.insert("梭体夹爪松开","62 00 00 3C 00 07 19 01 02 00 00 55 AA");
    orderMap.insert("旋盖夹爪保持原位夹紧","62 00 00 3C 00 07 31 00 00 00 00 55 AA");
    orderMap.insert("旋盖夹爪保持原位松开","62 00 00 3C 00 07 31 01 00 00 00 55 AA");
    orderMap.insert("旋盖夹爪靶材罐夹紧","62 00 00 3C 00 07 31 00 02 00 00 55 AA");
    orderMap.insert("旋盖夹爪靶材罐松开","62 00 00 3C 00 07 31 01 02 00 00 55 AA");
    orderMap.insert("旋盖夹爪夹紧","62 00 00 3C 00 07 19 03 01 00 00 55 AA");
    orderMap.insert("旋盖夹爪松开","62 00 00 3C 00 07 19 03 02 00 00 55 AA");
    orderMap.insert("吸盘1开启","62 00 00 3C 00 08 19 04 01 01 00 00 55 AA");
    orderMap.insert("吸盘1关闭","62 00 00 3C 00 08 19 04 02 01 00 00 55 AA");
    orderMap.insert("吸盘2开启","62 00 00 3C 00 08 19 04 01 02 00 00 55 AA");
    orderMap.insert("吸盘2关闭","62 00 00 3C 00 08 19 04 02 02 00 00 55 AA");
    orderMap.insert("Z轴气缸上升","62 00 00 3C 00 07 19 02 02 00 00 55 AA");
    orderMap.insert("Z轴气缸下降","62 00 00 3C 00 07 19 02 01 00 00 55 AA");
    orderMap.insert("开盖","62 00 00 3C 00 07 1A 01 00 00 00 55 AA");
    orderMap.insert("关盖","62 00 00 3C 00 07 1A 02 00 00 00 55 AA");
    orderMap.insert("旋盖动作及位置靶材罐位置","62 00 00 3C 00 06 34 02 00 00 55 AA");
    orderMap.insert("旋盖动作及位置初始位置","62 00 00 3C 00 06 34 03 00 00 55 AA");
    QString info= orderMap.value(action);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::rundjyx 电机运行到设置位置
 * @param type 读/写
 */
Q_INVOKABLE void MaintenanceAndCorrection::rundjyx(QString hc,QString djbh){
    hc=QString("%1").arg(hc.toUInt(), 2, 16, QLatin1Char('0'));
    djbh=QString("%1").arg(djbh.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 09 04 %1 %2 00 00 00 00 55 AA").arg(hc,djbh);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::getcgqsl 读空压机气压
 * @param type 读/写
 */
Q_INVOKABLE void MaintenanceAndCorrection::getcgqsl(){
    QString info= "62 00 00 3C 00 09 6E 02 00 00 00 00 00 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getAir 写空压机气压
 * @param type 读/写
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setcgqsl(QString value){
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 09 6E 01 %1 00 00 00 00 55 AA").arg(paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runrdb 蠕动泵
 */
Q_INVOKABLE void MaintenanceAndCorrection::runrdb(QString djbh,QString fx,QString sd,QString sj){
    djbh=QString("%1").arg(djbh.toUInt(), 2, 16, QLatin1Char('0'));
    if(fx=="吸液"){
        fx="01";
    }else if(fx=="打液"){
        fx="02";
    }else if(fx=="停止"){
        fx="03";
    }
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    sj=QString("%1").arg(sj.toUInt(), 4, 16, QLatin1Char('0'));
    sj.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 0D %1 %2 %3 %4 00 00 55 AA").arg(djbh,fx,sd,sj);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::ZSD 指示灯
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::ZSD(QString type){
    if(type=="开启"){
        type="00";
    }else if(type=="关闭"){
        type="01";
    }
    QString info= QString("62 00 00 3C 00 09 58 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::ZBQG 转靶气缸
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::ZBQG(QString type){
    if(type=="全开"){
        type="01";
    }else if(type=="全关"){
        type="02";
    }
    QString info= QString("62 00 00 3C 00 09 19 00 %1 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::HJWZ 活检位置
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::HJWZ(QString type){
    if(type=="放检位置"){
        type="01";
    }else if(type=="活检位置"){
        type="02";
    }
    QString info= QString("62 00 00 3C 00 09 1C %1 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getAir 读空压机气压
 * @param type 读/写
 */
Q_INVOKABLE void MaintenanceAndCorrection::getAir(QString type){
    if(type=="开阀门"){
        type="00";
    }else if(type=="关阀门"){
        type="01";
    }else{
        type="02";
    }
    QString info= QString("62 00 00 3C 00 09 51 02 %1 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getAir 写空压机气压
 * @param type 读/写
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setAir(QString type,QString value){
    if(type=="开阀门"){
        type="00";
    }else if(type=="关阀门"){
        type="01";
    }else{
        type="02";
    }
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 09 51 01 %1 %2 00 00 55 AA").arg(type,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getDBLSJ 冷水机流量读
 * @param type 读/写
 */
Q_INVOKABLE void MaintenanceAndCorrection::getDBLSJ(QString type1,QString type2){
    if(type1=="开阀门"){
        type1="00";
    }else if(type1=="关阀门"){
        type1="01";
    }
    if(type2=="进口"){
        type2="01";
    }else if(type2=="出口"){
        type2="02";
    }
    QString info= QString("62 00 00 3C 00 0A 6F 02 %1 00 00 %2 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setDBLSJ 冷水机流量写
 * @param type 读/写
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setDBLSJ(QString type1,QString type2,QString value){
    if(type1=="开阀门"){
        type1="00";
    }else if(type1=="关阀门"){
        type1="01";
    }
    if(type2=="进口"){
        type2="01";
    }else if(type2=="出口"){
        type2="02";
    }
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0A 6F 02 %1 %2 %3 00 00 55 AA").arg(type1,paryl,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getHqAir 读氦气气泵压力
 * @param type 读/写
 */
Q_INVOKABLE void MaintenanceAndCorrection::getHqAir(QString type){
    if(type=="开阀门"){
        type="00";
    }else{
        type="01";
    }
    QString info= QString("62 00 00 3C 00 09 71 02 %1 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setHqAir 写氦气气泵压力
 * @param type 读/写
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setHqAir(QString type,QString value){
    if(type=="开阀门"){
        type="00";
    }else{
        type="01";
    }
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 09 71 01 %1 %2 00 00 55 AA").arg(type,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getXqbAir 读吸取靶气泵压力
 * @param type 开阀门/关
 */
Q_INVOKABLE void MaintenanceAndCorrection::getXqbAir(QString type){
    if(type=="开阀门"){
        type="00";
    }else{
        type="01";
    }
    QString info= QString("62 00 00 3C 00 09 72 02 %1 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setXqbAir 写吸取靶气泵压力
 * @param action 开阀门/关
 */
Q_INVOKABLE void MaintenanceAndCorrection::setXqbAir(QString type,QString value){
    if(type=="开阀门"){
        type="00";
    }else{
        type="01";
    }
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 09 72 01 %1 %2 00 00 55 AA").arg(type,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::dry 干燥
 * @param time 时间(分)
 * @param kg 开关
 */
Q_INVOKABLE void MaintenanceAndCorrection::dry(QString time,QString kg){
    QString paryl;
    paryl=QString("%1").arg(time.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    QString type;
    if(kg=="开"){
        type="00";
    }else{
        type="01";
    }
    QString info= QString("62 00 00 3C 00 08 85 %1 %2 00 00 55 AA").arg(paryl,type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getXpAir 读吸取靶气泵压力
 * @param type 开阀门/关
 */
Q_INVOKABLE void MaintenanceAndCorrection::getXpAir(){
    QString info= "62 00 00 3C 00 0A 24 02 00 00 00 00 00 00 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setXpAir 写吸取靶气泵压力
 * @param type 开阀门/关
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setXpAir(QString type1,QString type2){
    type1=QString("%1").arg(type1.toUInt(), 4, 16, QLatin1Char('0'));
    type1.insert(2, ' ');
    type2=QString("%1").arg(type2.toUInt(), 4, 16, QLatin1Char('0'));
    type2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0A 24 01 %1 %2 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getZbZZ Z轴电机位置读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbZZ(QString type){
    type = QString::number(type.toInt());
    QString info= QString("62 00 00 3C 00 0B 25 02 %1 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbZZ Z轴电机位置写
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbZZ(QString type,QString sd,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 25 01 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbZZ Z轴电机位置执行
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbZZ(QString type,QString sd,QString value){
    type = QString::number(type.toInt()+1);
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 25 03 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::getZbXZ X轴电机位置读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbXZ(QString type){
    type = QString::number(type.toInt());
    QString info= QString("62 00 00 3C 00 0D 26 02 %1 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbXZ X轴电机位置写
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbXZ(QString type,QString value2,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    value2=QString("%1").arg(value2.toUInt(), 4, 16, QLatin1Char('0'));
    value2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 26 01 %1 %2 %3 00 00 55 AA").arg(type,value2,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbXZ X轴电机位置执行
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbXZ(QString type,QString value2,QString value){
    type = QString::number(type.toInt()+1);
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    value2=QString("%1").arg(value2.toUInt(), 4, 16, QLatin1Char('0'));
    value2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 26 03 %1 %2 %3 00 00 55 AA").arg(type,value2,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getZbKG 开盖电机位置读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbKG(QString type){
    type = QString::number(type.toInt());
    QString info= QString("62 00 00 3C 00 0B 27 02 %1 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbKG 开盖电机位置写
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbKG(QString type,QString sd,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 27 01 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbKG 开盖电机位置执行
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbKG(QString type,QString sd,QString value){
    type = QString::number(type.toInt()+1);
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 27 03 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getZbHX 活性电机位置读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbHX(QString type){
    type = QString::number(type.toInt());
    QString info= QString("62 00 00 3C 00 0B 2D 02 %1 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbHX 活性电机位置写
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbHX(QString type,QString sd,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 2D 01 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbHX 活性电机位置执行
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbHX(QString type,QString sd,QString value){
    type = QString::number(type.toInt()+1);
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 2D 03 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getZbXPDJ 吸盘电机位置读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbXPDJ(QString type){
    type = QString::number(type.toInt());
    QString info= QString("62 00 00 3C 00 0D 2E 02 %1 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbXPDJ 吸盘电机位置写
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbXPDJ(QString type,QString sd,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0D 2E 01 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbXPDJ 活性电机位置执行
 * @param type 位置
 * @param value 值
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbXPDJ(QString type,QString sd,QString value){
    type = QString::number(type.toInt());
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    sd=QString("%1").arg(sd.toUInt(), 4, 16, QLatin1Char('0'));
    sd.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0D 2E 03 %1 %2 %3 00 00 55 AA").arg(type,sd,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getZbRD 蠕动泵电机读
 * @param type 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZbRD(QString type){
    if(type=="吸液"){
        type="01";
    }else if(type=="打液"){
        type="02";
    }else{
        type="03";
    }
    QString info= QString("62 00 00 3C 00 0D 28 02 %1 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setZbRD 蠕动泵电机写
 * @param type 位置
 * @param value 值
 * @param value2 值2
 */
Q_INVOKABLE void MaintenanceAndCorrection::setZbRD(QString type,QString value,QString value2){
    if(type=="吸液"){
        type="01";
    }else if(type=="打液"){
        type="02";
    }else{
        type="03";
    }
    QString paryl,paryl2;
    paryl=QString("%1").arg(value.toUInt(), 8, 16, QLatin1Char('0'));
    paryl.insert(6, ' ');
    paryl.insert(4, ' ');
    paryl.insert(2, ' ');
    int par2 = value2.toDouble()*100;
    paryl2=QString("%1").arg(par2, 4, 16, QLatin1Char('0'));
    paryl2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0D 28 01 %1 %2 %3 00 00 55 AA").arg(type,paryl,paryl2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runZbRD 蠕动泵电机执行
 * @param type 位置
 * @param value1 速度
 * @param value2 时间
 */
Q_INVOKABLE void MaintenanceAndCorrection::runZbRD(QString type,QString value1,QString value2){
    if(type=="吸液"){
        type="01";
    }else if(type=="打液"){
        type="02";
    }else{
        type="03";
    }
    QString paryl,paryl2;
    paryl=QString("%1").arg(value1.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    paryl2=QString("%1").arg(value2.toUInt(), 4, 16, QLatin1Char('0'));
    paryl2.insert(2, ' ');
    if(type=="03"){
        paryl = "00 00";
        paryl2 = "00 00";
    }
    QString info= QString("62 00 00 3C 00 0B 28 03 %1 %2 %3 00 00 55 AA").arg(type,paryl,paryl2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runQFB 取放靶执行
 * @param type 位置
 * @param type2 位置
 */
Q_INVOKABLE void MaintenanceAndCorrection::runQFB(QString type,QString type2,QString type3){
    if(type=="取靶"){
        type="01";
    }else if(type=="放靶"){
        type="02";
    }else{
        type="03";
    }
    if(type2=="靶材罐"){
        type2="01";
    }else if(type2=="溶靶瓶"){
        type2="02";
    }else if(type2=="检测瓶"){
        type2="03";
    }else if(type2=="开盖检测"){
        type2="05";
    }else{
        type2="04";
    }
    if(type3=="吸盘1"){
        type3="01";
    }else if(type3=="吸盘2"){
        type3="02";
    }
    QString info= QString("62 00 00 3C 00 08 1B %1 %2 %3 00 00 55 AA").arg(type,type2,type3);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::zbjr 转靶加热
 * @param time 温度
 * @param value 时间
 */
Q_INVOKABLE void MaintenanceAndCorrection::zbjr(QString time,QString value){
    QString paryl,paryl2;
    int wd = time.toDouble()*10;
    paryl=QString("%1").arg(wd, 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    paryl2=QString("%1").arg(value.toUInt(), 4, 16, QLatin1Char('0'));
    paryl2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 09 1D %1 %2 00 00 55 AA").arg(paryl,paryl2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::qlcgq 气路传感器个数配置
 * @param type 读写
 * @param value 个数
 */
Q_INVOKABLE void MaintenanceAndCorrection::qlcgq(QString type,QString value){
    if(type=="写入"){
        type="01";
    }else if(type=="读取"){
        type="02";
    }
    QString paryl;
    paryl=QString("%1").arg(value.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 07 6E %1 %2 00 00 55 AA").arg(type,paryl);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getlsjll 冷水机流量维护读
 * @param type 阀门开关
 * @param type2 压力值
 * @param type3 进出口
 */
Q_INVOKABLE void MaintenanceAndCorrection::getlsjll(QString type,QString type3){
    if(type=="开阀门"){
        type="00";
    }else if(type=="关阀门"){
        type="01";
    }
    if(type3=="进口"){
        type3="01";
    }else if(type3=="出口"){
        type3="02";
    }
    QString info= QString("62 00 00 3C 00 0A 6F 02 %1 00 00 %3 00 00 55 AA").arg(type,type3);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setlsjll 冷水机流量维护写
 * @param type 阀门开关
 * @param type2 压力值
 * @param type3 进出口
 */
Q_INVOKABLE void MaintenanceAndCorrection::setlsjll(QString type,QString type2,QString type3){
    if(type=="开阀门"){
        type="00";
    }else if(type=="关阀门"){
        type="01";
    }
    QString paryl;
    paryl=QString("%1").arg(type2.toUInt(), 4, 16, QLatin1Char('0'));
    paryl.insert(2, ' ');
    if(type3=="进口"){
        type3="01";
    }else if(type3=="出口"){
        type3="02";
    }
    QString info= QString("62 00 00 3C 00 0A 6F 01 %1 %2 %3 00 00 55 AA").arg(type,paryl,type3);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::zbrundcf 转靶端电磁阀统一动作
 * @param type 开关
 */
Q_INVOKABLE void MaintenanceAndCorrection::zbrundcf(QString type){
    if(type=="打开"){
        type="00";
    }else if(type=="关闭"){
        type="01";
    }
    QString info= QString("62 00 00 3C 00 0D 3A %1 00 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::dbrundcf 打靶端电磁阀统一动作
 * @param type 开关
 */
Q_INVOKABLE void MaintenanceAndCorrection::dbrundcf(QString type){
    if(type=="打开"){
        type="00";
    }else if(type=="关闭"){
        type="01";
    }
    QString info= QString("62 00 00 3C 00 0D 7B %1 00 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runjgjr 激光加热指示光
 * @param type 开关
 */
Q_INVOKABLE void MaintenanceAndCorrection::runjgjr(QString type){
    if(type=="打开"){
        type="00";
    }else if(type=="关闭"){
        type="01";
    }
    QString info= QString("62 00 00 3C 00 0D 3A %1 00 00 00 00 00 00 00 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHFW 纯化复位
 * @param type 耗材名称
 */
Q_INVOKABLE void MaintenanceAndCorrection::runCHFW(QString type){
    QString code=CommonHelper::Common().getItemCode("3",type);
    type = QString("%1").arg(code.toUInt(), 4, 16, QLatin1Char('0'));
    type.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 06 0E %1 00 00 55 AA").arg(type);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHFM 纯化阀门
 * @param type 阀门开关列表
 */
Q_INVOKABLE void MaintenanceAndCorrection::runCHFM(QString type){
    QString par1,par2;
    QStringList alllist = type.split(",");
    for(int i=23;i>=0;i--){
        if(alllist[i]=="0"){
            par2.append("1");
        }else{
            par2.append("0");
        }
    }
    QString v1 = par2.mid(0,8);
    QString v2 = par2.mid(8,8);
    QString v3 = par2.mid(16,8);
    par2 = v3 + v2 + v1;
    bool ok;
    int val=par2.toInt(&ok,2);
    par2 = QString("%1").arg(val,6,16,QLatin1Char('0')).toUpper();
    QString info=QString("62 00 00 3B 00 09 08 02 %1 E7 2F 55 AA").arg(par2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setQBYL 纯化气泵压力维护
 * @param value1 开阀门值
 * @param value2 关阀门值
 */
Q_INVOKABLE void MaintenanceAndCorrection::getQBYL(){
    QString info= "62 00 00 3C 00 0A 02 02 00 00 00 00 00 00 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
Q_INVOKABLE void MaintenanceAndCorrection::setQBYL(QString value1,QString value2){
    value1 = QString("%1").arg(value1.toUInt(), 4, 16, QLatin1Char('0'));
    value1.insert(2, ' ');
    value2 = QString("%1").arg(value2.toUInt(), 4, 16, QLatin1Char('0'));
    value2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0A 02 01 %1 %2 00 00 55 AA").arg(value1,value2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHFW 纯化加热
 * @param type1 温度
 * @param type2 时间
 */
Q_INVOKABLE void MaintenanceAndCorrection::CHJR(QString type1,QString type2){
    int wd = type1.toDouble()*10;
    type1 = QString("%1").arg(wd, 4, 16, QLatin1Char('0'));
    type2 = QString("%1").arg(type2.toUInt(), 4, 16, QLatin1Char('0'));
    type1.insert(2, ' ');
    type2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0A 0F %1 %2 00 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getCHDJCS 纯化电机参数读
 * @param type1 电机编号
 * @param type2 步骤细分
 * @param type3 运行电流
 * @param type4 待机电流
 */
Q_INVOKABLE void MaintenanceAndCorrection::getCHDJC(QString type1){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 0A 12 %1 02 00 00 00 00 00 55 AA").arg(type1);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::SETCHDJC 纯化电机参数写
 * @param type1 电机编号
 * @param type2 步骤细分
 * @param type3 运行电流
 * @param type4 待机电流
 */
Q_INVOKABLE void MaintenanceAndCorrection::setCHDJC(QString type1,QString type2,QString type3, QString type4){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    type2 = QString("%1").arg(type2.toUInt(), 2, 16, QLatin1Char('0'));
    type3 = QString("%1").arg(type3.toUInt(), 2, 16, QLatin1Char('0'));
    type4 = QString("%1").arg(type4.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 0A 12 %1 01 %2 %3 %4 00 00 55 AA").arg(type1,type2,type3,type4);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getCHMAXXC 纯化电机最大行程读
 * @param type1 电机编号
 * @param type2 最大行程
 */
Q_INVOKABLE void MaintenanceAndCorrection::getCHMAXXC(QString type1){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 0B 13 %1 02 00 00 00 00 00 00 55 AA").arg(type1);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getCHMAXXC 纯化电机最大行程写
 * @param type1 电机编号
 * @param type2 最大行程
 */
Q_INVOKABLE void MaintenanceAndCorrection::setCHMAXXC(QString type1,QString type2){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    type2 = QString("%1").arg(type2.toUInt(), 8, 16, QLatin1Char('0'));
    type2.insert(6, ' ');
    type2.insert(4, ' ');
    type2.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0B 13 %1 01 %2 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHYXCS 纯化运行测试
 * @param type1 电机编号
 * @param type2 方向
 * @param type3 运行速度
 * @param type4 步数
 */
Q_INVOKABLE void MaintenanceAndCorrection::runCHYXCS(QString type1,QString type2,QString type3, QString type4){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    if(type2=="顺时针"){
        type2="01";
    }else{
        type2="02";
    }
    type3 = QString("%1").arg(type3.toUInt(), 4, 16, QLatin1Char('0'));
    type3.insert(2, ' ');
    type4 = QString("%1").arg(type4.toUInt(), 8, 16, QLatin1Char('0'));
    type4.insert(6, ' ');
    type4.insert(4, ' ');
    type4.insert(2, ' ');
    QString info= QString("62 00 00 3C 00 0D 14 %1 %2 %3 %4 00 00 55 AA").arg(type1,type2,type3,type4);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHStopCS 纯化停止测试
 * @param type1 电机编号
 */
Q_INVOKABLE void MaintenanceAndCorrection::runCHStopCS(QString type1){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 06 15 %1 00 00 55 AA").arg(type1);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setCHDJBH 写入电机编号
 * @param type1 电机编号
 * @param type2 电机编号
 */
Q_INVOKABLE void MaintenanceAndCorrection::setCHDJBH(QString type1,QString type2){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    type2 = QString("%1").arg(type2.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 07 17 %1 %2 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::setCHFWFS 写入复位方式
 * @param type1 电机编号
 * @param type2 电机编号
 */
Q_INVOKABLE void MaintenanceAndCorrection::setCHFWFS(QString type1,QString type2){
    type1 = QString("%1").arg(type1.toUInt(), 2, 16, QLatin1Char('0'));
    type2 = QString("%1").arg(type2.toUInt(), 2, 16, QLatin1Char('0'));
    QString info= QString("62 00 00 3C 00 07 18 %1 %2 00 00 55 AA").arg(type1,type2);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::runCHStopCS 写入复位方式
 * @param type1 电机编号
 * @param type2 电机编号
 */
Q_INVOKABLE void MaintenanceAndCorrection::CHLG(QString type1){
    if(type1=="开启"){
        type1="01";
    }else{
        type1="02";
    }
    QString info= QString("62 00 00 3C 00 07 10 %1 %2 00 00 55 AA").arg(type1);
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}

/**
 * @brief MaintenanceAndCorrection::getZBxpyl 转靶吸盘压力
 */
Q_INVOKABLE void MaintenanceAndCorrection::getZBxpyl(){
    QString info= "62 00 00 3C 00 06 2A 22 E7 2F 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getDBhqyl 打靶氦气压力
 */
Q_INVOKABLE void MaintenanceAndCorrection::getDBhqyl(){
    QString info= "62 00 00 3C 00 06 2A 24 E7 2F 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getStateInfo 状态获取
 */
Q_INVOKABLE void MaintenanceAndCorrection::getStateInfo(){
    QString info= "62 00 00 3C 00 06 2A 01 00 00 55 AA";
    udpClient->ClientSendingData(CommonHelper::Common().GetSendData(info));
}
/**
 * @brief MaintenanceAndCorrection::getStateInfos 状态连续获取
 */
Q_INVOKABLE void MaintenanceAndCorrection::getStateInfos(QString type){
    if(type=="连续读取"){
        timSend->setInterval(2000);
        connect(timSend,&QTimer::timeout,this,[=]()
        {
            getStateInfo();
        });
        timSend->start();
    }else{
        disconnect(timSend,0,0,0);
        timSend->stop();
    }
}

#pragma endregion}

#pragma region 能谱{

Q_INVOKABLE void MaintenanceAndCorrection::operationCpsReadData(int type){
    cpsUdpClient=CpsUdpClient::getInstance();

    if(type==0){
        cpsUdpClient->ClientSendingData(CommonHelper::Common().GetSendData( CommCommand::I().startExperiment()));
    }
    else{
        cpsUdpClient->ClientSendingData(CommonHelper::Common().GetSendData( CommCommand::I().stopExperiment()));
    }
}

#pragma endregion}
